package com.tj.jinzao.fragment;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.tj.jinzao.R;
import com.tj.jinzao.adapter.FriendAdapter;
import com.tj.jinzao.base.BaseDataListFragment;
import com.tj.jinzao.callback.IListFriendView;
import com.tj.jinzao.manager.UserManager;
import com.tj.jinzao.model.FriendBean;
import com.tj.jinzao.model.ResultResponse;
import com.tj.jinzao.model.User;
import com.tj.jinzao.presenter.FriendPresenter;
import com.tj.jinzao.widgets.EmptyView;

import java.util.HashMap;
import java.util.List;

import butterknife.BindView;

/**
 * 搜索好友
 * Created by wjy on 2019/1/1.
 */
public class FriendFragment extends BaseDataListFragment<List<FriendBean>, FriendPresenter, FriendBean> implements IListFriendView<List<FriendBean>> {

    @BindView(R.id.fl_list_layout)
    View mListLayout;

    private User user;

    public static FriendFragment newInstance() {
        FriendFragment fragment = new FriendFragment();
        if (fragment != null) {
            Bundle args = new Bundle(3);
            args.putString(ARG_TAG_ID, "1");
            args.putInt(ARG_LOAD_ID, 1);
            args.putInt(ARG_LAYOUT_RES_ID, R.layout.friend_fragment);
            fragment.setArguments(args);
        }

        return fragment;
    }

    @Override
    public void onRequestNoData(String message) {
        setEmptyDataView();
    }

    @Override
    protected FriendPresenter createPresenter() {
        user= UserManager.getInstance().getUser();
        return new FriendPresenter(this);
    }

    @Override
    protected void createView(LayoutInflater inflater, View view) {

    }

    @Override
    protected RecyclerView.Adapter createAdapter() {
        return new FriendAdapter(mContext, mData,0);
    }

    @Override
    protected void requestData() {
         HashMap<String,Object> map=new HashMap<>();
         map.put("uid",user.getId());
         mPresenter.getFriend(map);
    }


    @Override
    protected void setEmptyDataView() {
        mEmptyView.setVisibility(View.VISIBLE);
        mEmptyView.setState(EmptyView.State.NO_DATA, "");
    }

    @Override
    public void onRequestSuccess(List<FriendBean> friendBeans) {
        super.onRequestSuccess(friendBeans);
        if (mPageNo <= 1) {
            mData.clear();
        }
        mData.addAll(friendBeans);
        showListView();
    }

    @Override
    protected boolean resolveData(List<FriendBean> friendBeans) {
        return false;
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void itemClicked(int position, FriendBean data) {
//        startActivity(new Intent(mContext, ArticleDetailActivity.class).putExtra("article", data));
    }



    @Override
    public void onRequestSuccessPage(int currentPage, int allPage, int allSize) {

    }

    @Override
    public void onReload(Object tag) {

    }

    @Override
    public void onAddFriendSuccess(FriendBean friendBean) {

    }

    @Override
    public void onFailed(ResultResponse response) {

    }

    @Override
    public void onUserInfoSuccess(User user) {

    }

    @Override
    public void onUserInfoFailed(ResultResponse response) {

    }
}
